package com.niannian.dialog;

import com.niannian.util.Common;
import com.niannian.view.HandyTextView;
import com.niannian.R;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class YesNoDialog extends BaseDialog implements
		android.view.View.OnClickListener {
	private static YesNoDialog tipDialog;
	private String mContent;
	private String mTitle;
	private HandyTextView ht_title;
	private HandyTextView ht_content;
	private TextView cancel;
	private Button confim;
	private onSimpleOnCancelListener mOnCancelListener;
	private onSimpleOnClicklListener mOnClickListener;

	public YesNoDialog(Context context) {
		super(context);
		init();
	}

	public YesNoDialog(Context context, String text) {
		super(context);
		mContent = text;
		init();
	}

	public YesNoDialog(Context context, String text, String title) {
		super(context);
		mContent = text;
		mTitle = title;
		init();
	}

	private void init() {
		setContentView(R.layout.confim_addorcanlce);
		ht_title = (HandyTextView) findViewById(R.id.tv_message_title);
		ht_content = (HandyTextView) findViewById(R.id.tv_message_content);
		cancel = (TextView) findViewById(R.id.btn_cancel);
		confim = (Button) findViewById(R.id.btn_confim);
		cancel.setOnClickListener(this);
		confim.setOnClickListener(this);
		if (!Common.empty(mContent)) {
			setMsg(mContent);
		}
		if (!Common.empty(mTitle)) {
			setTitle(mTitle);
		}
	}

	public void setConfimButtonText(String text) {
		confim.setText(text);
	}

	public void setMsg(String text) {
		mContent = text;
		ht_content.setText(mContent);
	}

	public void setTitle(String title) {
		mTitle = title;
		ht_title.setText(mTitle);
	}

	public void setCancelBackgound(int id) {
		cancel.setBackgroundResource(id);
	}

	public void setConfimBackgound(int id) {
		confim.setBackgroundResource(id);
	}

	public void setOnConfimClickListener(onSimpleOnClicklListener listener) {
		mOnClickListener = listener;
	}

	public void setOnCancelListener(onSimpleOnCancelListener listener) {
		mOnCancelListener = listener;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_confim:
			mOnClickListener.onClick();
			break;
		case R.id.btn_cancel:
			mOnCancelListener.onCancel();
			break;
		default:
			break;
		}
	}

	@Override
	public void dismiss() {
		if (isShowing()) {
			super.dismiss();
		}
	}

	public interface onSimpleOnCancelListener {
		public void onCancel();
	}

	public interface onSimpleOnClicklListener {
		public void onClick();
	}

}
